package fr.inserm.u674.chcdbweb.view.ajax;

import java.util.Arrays;
import java.util.List;

import org.jdom.Element;
import org.jdom.output.XMLOutputter;

import fr.inserm.u674.chcdbweb.model.DTO.EAVVariable;

public final class QDWriter {

	public static String writeEAVVarListTable(List<EAVVariable> varList, boolean humanReadable) {
		String finalString;

		Element table = new Element("table");

		Element thead = new Element("thead");
		Element tr = new Element("tr");
		for (String head : Arrays.asList("full name", "simple name", "type", "creation date",
			"deprecated", "description")) {
			Element td = new Element("td");
			td.setText(head);
			tr.addContent(td);
		}
		thead.addContent(tr);
		table.addContent(thead);

		Element tbody = new Element("tbody");

		for (EAVVariable eVar : varList) {
			tr = new Element("tr");
			Element td;
			td = new Element("td");
			td.setAttribute("style", "font-size: 12px; font-family: courier");
			td.setText(eVar.getVariableName());
			tr.addContent(td);
			td = new Element("td");
			td.setText(eVar.getHumanReadableName());
			tr.addContent(td);
			td = new Element("td");
			td.setText(eVar.getDataType());
			tr.addContent(td);
			td = new Element("td");
			td.setText(eVar.getCreationDate().toString());
			tr.addContent(td);
			td = new Element("td");
			td.setText(eVar.getDeprecated().toString());
			tr.addContent(td);
			td = new Element("td");
			td.setText(eVar.getDescription());
			tr.addContent(td);

			tbody.addContent(tr);

		}
		table.addContent(tbody);

		XMLOutputter outputter = new XMLOutputter();
		finalString = outputter.outputString(table);

		return finalString;
	}
}
